package com.yc.baseProgram.recursion;

/**
 * Created with IntelliJ IDEA.
 * description:
 * https://blog.csdn.net/zbc1090549839/article/details/49388225
 * author: yc
 * date: 2021/2/23 20:13
 */

import java.util.ArrayList;
import java.util.List;

public class Permutate {

    // 保存生成的排列组合内容
    public List<String> Permutation = new ArrayList<String>();

    /**
     * 递归的方式计算排列组合
     * @param list  传入list.size()个集合
     * @param preStr 上一步递归中生成的排列组合
     * @return
     */
    public  void permutation( List<List<String>> list,String preStr) {
        int size = list.size();
        if(1==size){
            for(int i=0; i<list.get(0).size(); i++) {
                Permutation.add(preStr + list.get(0).get(i));
            }
        }
        else{
            List<String> permu = new ArrayList<String>(list.get(0));
            List<List<String>> now = new ArrayList<List<String>>(list);
            now.remove(0);
            for(int i=0; i<permu.size(); i++){
                permutation(now, preStr +permu.get(i));
            }
        }
    }



    public static void main(String[] args) throws Exception {
        List<List<String>> list = new ArrayList<List<String>>();
        List<String> SET1 = new ArrayList<String>();
        SET1.add("茄子");
        SET1.add("大白菜");
        List<String> SET2 = new ArrayList<String>();
        SET2.add("牛肉");
        SET2.add("羊肉");
        List<String> SET3 = new ArrayList<String>();
        SET3.add("桃酥");
        SET3.add("麻饼");
        list.add(SET1);
        list.add(SET2);
        list.add(SET3);

        Permutate permutate = new Permutate();
        permutate.permutation(list,"");
        System.out.println(permutate.Permutation);
    }

}